﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OleDb;

public partial class product_card_user_Reward : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  
    protected void Page_Load(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        con.Open();
        SqlDataAdapter cmd = new SqlDataAdapter("Select SUM(reward) FROM calculateReward where custID='" + custId + "'", con);
        DataTable dt = new DataTable();
        cmd.Fill(dt);
        
        
        TextBox51.Text = dt.Rows[0][0].ToString();
     
        Label12.Text = System.DateTime.Now.ToString();
        Image1.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Noticeboard1.jpg'");
        Image1.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/10 points.gif'");
        Image2.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/PowerSaversLoogoo.jpg'");
        Image2.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/15 points.gif'");
        Image3.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/AdminService.jpg'");
        Image3.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/20 point.gif'");
        Image4.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Reward25.jpg'");
        Image4.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/25 points.gif'");
        Image5.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Noticeboard30.jpg'");
        Image5.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/30 points.gif'");
        Image6.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Reward35.jpg'");
        Image6.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/35 points.gif'");
        Image7.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Reward40.jpg'");
        Image7.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/40 points.gif'");
        Image8.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Reward45.jpg'");
        Image8.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/45 points.gif'");
        Image9.Attributes.Add("onmouseover", "this.src='/PowerSaver/product/card/AllImages/Reward50.jpg'");
        Image9.Attributes.Add("onmouseout", "this.src='/PowerSaver/product/card/AllImages/50 points.gif'");
    }
    
   
    protected void Claim_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 10)
        {

            Label11.Text = ("");
            rewardPoints = rewardPoints - 10;

            TextBox51.Text = rewardPoints.ToString();
            Label23.Text = "10 points reward claimed";
            Label1.Text = ("Rewards Claimed");
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label15.Text + "','" + Point11.Text + "','" + Label12.Text + "')", con);
          
            String sql = "insert into calculateReward (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
      
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point10.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();
            cmd.ExecuteNonQuery();
        

     

            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";
             
            }
            else             {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }

        else if (rewardPoints < 10)
        {
            TextBox51.Text = rewardPoints.ToString();
            Label11.Text = ("Your reward points is lesser than 10, cannot claim.");
            Label12.Text = "";
            Label13.Text = "";
        }
    }

    protected void Claim1_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 15)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 15;

            TextBox51.Text = rewardPoints.ToString();
            Label2.Text = ("Rewards Claimed");
            Label23.Text = "15 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label15.Text + "','" + Point11.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEDREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label12.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point11.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

           cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
        else if (rewardPoints < 15)
        {
            TextBox51.Text = rewardPoints.ToString();
            Label11.Text = ("Your reward points is lesser than 15, cannot claim.");
            Label12.Text = "";
            Label13.Text = "";
        }
}

    
    protected void Claim2_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 20)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 20;
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            TextBox51.Text = rewardPoints.ToString();
            Label3.Text = ("Rewards Claimed");
               Label23.Text = "20 points reward claimed";
               SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label16.Text + "','" + Point12.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point12.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

           cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 20){
          
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 20, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }

}
    
    protected void Claim3_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 25)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 25;
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            TextBox51.Text = rewardPoints.ToString();
            Label4.Text = ("Rewards Claimed");
            Label23.Text = "25 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label17.Text + "','" + Point13.Text + "','" + Label12.Text + "')", con);
                     String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
                     SqlCommand cmd1 = new SqlCommand(sql, con);
                     cmd1.Parameters.AddWithValue("@custID", custId);
                     cmd1.Parameters.AddWithValue("@date", Label2.Text);
                     cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point13.Text));
                     cmd1.Parameters.AddWithValue("@type", Label23.Text);
                     cmd1.ExecuteNonQuery();

          cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 25)
        {
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 25, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }
}
    
    protected void Claim4_Click(object sender, EventArgs e)
    {
        Label11.Text = ("");
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 30)
        {
            rewardPoints = rewardPoints - 30;
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            TextBox51.Text = rewardPoints.ToString();
            Label5.Text = ("Rewards Claimed");
            Label23.Text = "30 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label19.Text + "','" + Point14.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point14.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

           cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 30){
          
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 30, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }
}
    
    protected void Claim5_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
 
        if (rewardPoints >= 35)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 35;
            TextBox51.Text = rewardPoints.ToString();
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            Label6.Text = ("Rewards Claimed");
            Label23.Text = "35 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label21.Text + "','" + Point15.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point15.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

            cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 35)
        {
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 35, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }
}
    
    protected void Claim6_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 40)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 40;
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            TextBox51.Text = rewardPoints.ToString();
            Label7.Text = ("Rewards Claimed");
            Label23.Text = "40 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label18.Text + "','" + Point16.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point16.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

           cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 40)
        {
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 40, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }
}
    
    protected void Claim7_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
  
        if (rewardPoints >= 45)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 45;
            TextBox51.Text = rewardPoints.ToString();
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            Label8.Text = ("Rewards Claimed");
            Label23.Text = "45 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label20.Text + "','" + Point17.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point17.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

            cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 45)
        {
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 45, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }
}
    
    protected void Claim8_Click(object sender, EventArgs e)
    {
        String custId = Session["userId"] as String;
        int rewardPoints = Convert.ToInt32(TextBox51.Text);
        if (rewardPoints >= 50)
        {
            Label11.Text = ("");
            rewardPoints = rewardPoints - 50;
            Label12.Text = "" + DateTime.Now.ToLongTimeString();
            TextBox51.Text = rewardPoints.ToString();
            Label9.Text = ("Rewards Claimed");
            Label23.Text = "50 points reward claimed";
            SqlCommand cmd = new SqlCommand("insert into REWARDSPOINT values('" + custId + "','" + TextBox51.Text + "','" + Label22.Text + "','" + Point18.Text + "','" + Label12.Text + "')", con);
            String sql = "insert into CALCULATEREWARD (custID,date,reward,type) values (@custID,@date,@reward,@type)";
            SqlCommand cmd1 = new SqlCommand(sql, con);
            cmd1.Parameters.AddWithValue("@custID", custId);
            cmd1.Parameters.AddWithValue("@date", Label2.Text);
            cmd1.Parameters.AddWithValue("@reward", 0 - decimal.Parse(Point18.Text));
            cmd1.Parameters.AddWithValue("@type", Label23.Text);
            cmd1.ExecuteNonQuery();

            cmd.ExecuteNonQuery();
            if (Label13.Text != null)
            {
                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "New reward claimed at : ";

            }
            else
            {

                Label12.Text = System.DateTime.Now.ToString();
                Label13.Text = "Claimed reward at : ";
            }
        }
 else if(rewardPoints < 50){
          
                TextBox51.Text = rewardPoints.ToString();
        Label11.Text = ("Your reward points is lesser than 50, cannot claim.");
        Label12.Text = "";
        Label13.Text = "";
    }
}
    public string custId { get; set; }
    protected void Button1_Click(object sender, EventArgs e)
    {

        Response.Redirect("~/product/card/user/POSMachine");
    }
}

